#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:start.py
# author:张世航
# datetime:2024/3/ 23:51
# software: PyCharm
"""
this is function  description 
"""
# import module your need


# start.py
from dao.student_dao import add_student, delete_student, query_student_by_name
from dao.teacher_dao import add_teacher, delete_teacher, query_teacher_by_name
from dao.department_dao import add_department, delete_department, query_department_by_name
from dao.course_dao import add_course, delete_course, query_course_by_name  # 确保导入了这些函数
from models.student import Student
from models.teacher import Teacher
from models.department import Department
from models.course import Course


def main():
    while True:
        print('1. 学生信息管理')
        print('2. 课程信息管理')
        print('3. 老师信息管理')
        print('4. 院系信息管理')
        print('0. 退出')
        index = input('请输入操作菜单选项: ')

        if index == '0':
            break
        elif index == '1':
            while True:
                print('1. 增加学生信息')
                print('2. 根据学生学号删除信息')
                print('3. 根据姓名查询信息')
                print('0. 返回上一层')
                index_sql = input('请输入操作指令: ')

                if index_sql == '1':
                    Sno = input("请输入学生学号: ")
                    Sname = input("请输入学生姓名: ")
                    Ssex = input("请输入学生性别: ")
                    Sage = int(input("请输入学生年龄: "))
                    Dno = input("请输入所属院系: ")
                    Sclass = input("请输入班级: ")
                    address = input("请输入家庭住址: ")
                    student = Student(Sno, Sname, Ssex, Sage, Dno, Sclass, address)
                    add_student(student)
                elif index_sql == '2':
                    Sno = input("请输入要删除的学生学号: ")
                    delete_student(Sno)
                elif index_sql == '3':
                    name = input("请输入要查询的学生姓名: ")
                    query_student_by_name(name)
                elif index_sql == '0':
                    break
                else:
                    print("无效的操作指令，请重试。")

        elif index == '2':
            while True:
                print('1. 增加课程信息')
                print('2. 根据课程编号删除信息')
                print('3. 根据课程名称查询信息')
                print('0. 返回上一层')
                index_sql = input('请输入操作指令: ')

                if index_sql == '1':
                    Cno = input("请输入课程编号: ")
                    Cname = input("请输入课程名称: ")
                    Chours = input("请输入学时: ")
                    Credit = input("请输入学分: ")
                    Tno = input("请输入教师编号: ")
                    StudentCount = input("请输入学生选课人数: ")
                    course = Course(Cno, Cname, Chours, Credit, Tno, StudentCount)
                    add_course(course)  # 确保这里调用了 add_course 函数
                elif index_sql == '2':
                    Cno = input("请输入要删除的课程编号: ")
                    delete_course(Cno)
                elif index_sql == '3':
                    name = input("请输入要查询的课程名称: ")
                    query_course_by_name(name)
                elif index_sql == '0':
                    break
                else:
                    print("无效的操作指令，请重试。")

        elif index == '3':
            while True:
                print('1. 增加教师信息')
                print('2. 根据教师编号删除信息')
                print('3. 根据姓名查询信息')
                print('0. 返回上一层')
                index_sql = input('请输入操作指令: ')

                if index_sql == '1':
                    Tno = input("请输入教师编号: ")
                    Tname = input("请输入教师姓名: ")
                    Dno = input("请输入所属院系: ")
                    Salary = input("请输入工资: ")
                    Tmobile = input("请输入手机号: ")
                    teacher = Teacher(Tno, Tname, Dno, Salary, Tmobile)
                    add_teacher(teacher)
                elif index_sql == '2':
                    Tno = input("请输入要删除的教师编号: ")
                    delete_teacher(Tno)
                elif index_sql == '3':
                    name = input("请输入要查询的教师姓名: ")
                    query_teacher_by_name(name)
                elif index_sql == '0':
                    break
                else:
                    print("无效的操作指令，请重试。")

        elif index == '4':
            while True:
                print('1. 增加院系信息')
                print('2. 根据院系ID删除信息')
                print('3. 根据院系名称查询信息')
                print('0. 返回上一层')
                index_sql = input('请输入操作指令: ')

                if index_sql == '1':
                    pid = input("请输入父院系ID（0表示无父院系）: ")
                    name = input("请输入院系名称: ")
                    department = Department(None, pid, name)  # ID 由数据库自动生成
                    add_department(department)
                elif index_sql == '2':
                    id = input("请输入要删除的院系ID: ")
                    delete_department(id)
                elif index_sql == '3':
                    name = input("请输入要查询的院系名称: ")
                    query_department_by_name(name)
                elif index_sql == '0':
                    break
                else:
                    print("无效的操作指令，请重试。")


if __name__ == '__main__':
    main()